n = 3

def recur():
    def dfs(frm,by,target,count):
        if count == 1:
            print(f"from {frm} to {target}")
            return
        dfs(frm,target,by,count-1)
        print(f"from {frm} to {target}")  # 移动一个盘子
        dfs(by,frm,target,count-1)
    dfs('a','b','c',n)
def stack():
    status = [('a','b','c',n)]
    while status:
        frm, by, target,count = status.pop()
        if count == 1:
            print(f"from {frm} to {target}")
            continue
        status.append((frm,target,by,count-1))
        print(f"from {frm} to {target}")  # 移动一个盘子
        status.append((by,frm,target,count-1))

stack()

